<?php

$app = [];
$app['config'] = require 'config.php'; 
require 'Core/DataBase/ConnetDB.php';
require 'Core/DataBase/RequestDB.php';

$pdo = ConnetDB::make($app['config']['database']);
$quesy = new RequestDB($pdo);
$isRegister = $quesy -> isRegister();
if($isRegister[0][0] != "1"){
	exit("本服务器暂停注册！");
}

$name = null;
$account = null;
$passwd = null;

if(isset($_POST['nickName'])){
	$tempname = $_POST['nickName'];
	if(preg_match("(！|@|#|￥|……|（|）|#|…|——|·|、|《|》|-|=|~|，|。)",$tempname)){
		echo "你的用户名存在非法字符！";
	}elseif(isset($tempname{5}) == false){
		echo "用户名必须大于5个字符。";
	}elseif(isset($tempacc{16}) == true){
		echo "用户名必须小于16个字符。";
	}else{
		$name = $_POST['nickName'];
	}
}

if(isset($_POST['userName'])){
	$tempacc = $_POST['userName'];
	if(isset($tempacc{5}) == false){
		echo "账号必须大于5个字符。";
	}elseif(isset($tempacc{10}) == true){
		echo "账号必须小于10个字符。";
	}else{
		$account = $_POST['userName'];
	}
}

if(isset($_POST['pwd'])){
	$temppasswd = $_POST['pwd'];
	if(isset($temppasswd{5}) == false){
		echo "密码必须大于5个字符。";
	}elseif(isset($temppasswd{18}) == true){
		echo "密码必须小于18个字符。";
	}else{
		$passwd = $_POST['pwd'];
	}
}

if($name && $account && $passwd != null){
	$isSU = $quesy -> ToRegister($name,$account,$passwd);
	if($isSU == "1"){
		echo "你的用户名已被人注册";
	}elseif($isSU == "2"){
		echo "你的账号已被人注册";
	}elseif($isSU == "3"){
		echo "注册成功";
	}
}


require 'WebView/register.view.php';

?>